#include "CuTest.h"
#include <pkg.h>
#include <dict.h>
#include <attrib.h>

void TestPkgNew(CuTest *tc) {
	pkg_p pkg = pkg_new();

	CuAssertPtrNotNull(tc, pkg);
}

void TestPkgSet(CuTest *tc) {
	pkg_p pkg = pkg_new();
	attrib_p attrib;
	attrib_p tmp = attrib_new("foo", "bar");

	pkg_set(pkg, "foo", "bar");
	attrib = dict_get((dict_p)pkg);

	CuAssertPtrNotNull(tc, attrib);
	CuAssertIntEquals(tc, 0, attrib_cmp(attrib, tmp));
}

void TestPkgGet(CuTest *tc) {
	pkg_p pkg = pkg_new();

	pkg_set(pkg, "foo", "bar");

	CuAssertStrEquals(tc, "bar", pkg_get(pkg, "foo"));
}

void TestPkgGet_Fail(CuTest *tc) {
	pkg_p pkg = pkg_new();

	CuAssertPtrEquals(tc, NULL, pkg_get(pkg, "foo"));
}

void TestPkgAdd(CuTest *tc) {
	pkg_p pkg = pkg_new();

	pkg_add(pkg, "foo", "bar");
	pkg_add(pkg, "foo", "baz");

	CuAssertIntEquals(tc, 2, list_size((list_p)pkg));
}

void TestPkgGetAll(CuTest *tc) {
	pkg_p pkg = pkg_new();
	list_p list;

	pkg_add(pkg, "foo", "bar");
	pkg_add(pkg, "foo", "baz");
	pkg_add(pkg, "bar", "foo");

	list = pkg_get_all(pkg, "foo");
	CuAssertIntEquals(tc, 2, list_size(list));

	list = pkg_get_all(pkg, "bar");
	CuAssertIntEquals(tc, 1, list_size(list));
}

void TestPkgSetName(CuTest *tc) {
	pkg_p pkg = pkg_new();
	char *name = "foo";

	pkg_set_name(pkg, name);
	CuAssertStrEquals(tc, name, pkg_get(pkg, "name"));
}

void TestPkgGetName(CuTest *tc) {
	pkg_p pkg = pkg_new();
	char *name = "foo";

	pkg_set_name(pkg, name);
	CuAssertStrEquals(tc, name, pkg_get_name(pkg));
}

void TestPkgHas(CuTest *tc) {
	pkg_p pkg = pkg_new();

	pkg_set(pkg, "foo", "bar");

	CuAssertIntEquals(tc, 0, pkg_has(pkg, "foo", "baz"));
}

